package cn.learn.jsoup;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

/**
 * @author huangyezhan
 * @version 1.0
 * @date 2020年12月25日11:34
 */
public class ParseHtml {

    private static String oss = "http://oss-cn-beijing.aliyuncs.com/";

    private static String bukert = "hyht-home-dev";

    //http://hyht-home-dev.oss-cn-beijing.aliyuncs.com

    public static void main(String[] args) {
        StringBuilder sb = new StringBuilder(oss);
        int           i  = oss.indexOf("http://");
        int           i1 = sb.indexOf("https://");
        System.out.println(i);
        System.out.println(i1);
        sb.insert(7,bukert + ".");

        System.out.println(sb);
    }

    public static void parse(){
        String html = "<p><img src=\"http://hyht-home-dev.oss-cn-beijing.aliyuncs.com/15f0438978ac11ea8e9768cc6ee12787/15f17cb778ac11ea8e9768cc6ee12787/20201225/lin_shi_photo/9f41cee7cee24f5abf51e596ff1296c0.png?Expires=1608829030&amp;OSSAccessKeyId=LTAI4G3Fm4yiHQjSS7ZVb3rs&amp;Signature=T9WYMd5%2FwaAcOqJONBBzXiA3TQY%3D\" style=\"max-width:100%;\">中国测试图片<br></p>" +
                "<img src=\"http://hyht-home-dev.oss-cn-beijing.aliyuncs.com/123213214214.png?hao='zjoga'\" >";
        Document doc  = Jsoup.parseBodyFragment(html);
        Element  body = doc.body();
        Elements img  = body.select("img");
        for (Element e : img) {
            String src = e.attr("src");
            String replace = src.replace(oss, "");
            int i = replace.indexOf("?");
            if (i > 0){
                String url = replace.substring(0,i);
                e.attr("src",url);
            }
        }
        System.out.println(body.select("body>*"));
    }
}
